package com.xckj.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.adrninistrator.jacg.common.enums.ConfigDbKeyEnum;
import com.adrninistrator.jacg.common.enums.ConfigKeyEnum;
import com.adrninistrator.jacg.common.enums.OtherConfigFileUseSetEnum;
import com.adrninistrator.jacg.conf.ConfigureWrapper;
import com.xckj.entity.ConfigDb;
import com.xckj.service.ConfigDbService;
import com.xckj.utils.ReturnT;
import com.xckj.utils.WriteConfigFile;

/**
 * @description 数据库配置
 * @author yanchf
 * @date 2023-12-09
 */
@Service
public class ConfigDbServiceImpl implements ConfigDbService {


	@Override
	public Object insert(ConfigDb configDb) {

		// valid
		if (configDb == null) {
			return ReturnT.error("必要参数缺失");
        }

        return ReturnT.success();
	}


	@Override
	public Object delete(int id) {
		return ReturnT.success();
	}


	@Override
	public Object update(ConfigDb configDb) {
		return ReturnT.success();
	}


	@Override
	public ConfigDb load(int id) {
		return null;
	}


	@Override
	public Map<String,Object> pageList(int offset, int pagesize) {
		List<ConfigDb> pageList = new ArrayList<ConfigDb>();
		int totalCount = 0;
		String confFile = ConfigDbKeyEnum.CDKE_DB_DRIVER_NAME.getFileName();
		String dbUrl = WriteConfigFile.getParam(confFile, ConfigDbKeyEnum.CDKE_DB_H2_FILE_PATH.getKey());
		String dbUser = WriteConfigFile.getParam(confFile, ConfigDbKeyEnum.CDKE_DB_USERNAME.getKey());
		String dbPass = WriteConfigFile.getParam(confFile, ConfigDbKeyEnum.CDKE_DB_PASSWORD.getKey());
		ConfigDb dbInfo = new ConfigDb(dbUrl, dbUser, dbPass);
		pageList.add(dbInfo);
		
		// result
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("pageList", pageList);
		result.put("totalCount", totalCount);
		return ReturnT.success(result);
	}

}